package networking;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;
import java.net.SocketException;
import java.net.UnknownHostException;

import dps.DpsMessageProto.DpsMessage;

public class DatagramClient {
	private static InetSocketAddress address;
	private static DatagramSocket socket = null;
	
	public DatagramClient(String ip, int port) throws UnknownHostException, SocketException {
		address = new InetSocketAddress(ip, port);
		socket = new DatagramSocket();
		socket.setBroadcast(true);
	}
	
	public void sendMessage(DpsMessage msg) throws IOException {
		socket.send(new DatagramPacket(msg.toByteArray(), msg.getSerializedSize(), address));
	}	
}
